package com.elephant.core.reactor;

/**
 * @Author: hai
 * @Date: 2019/2/12 16:17
 */
public class Server {
    Selector selector = new Selector();
    Dispatcher eventLooper = new Dispatcher(selector);
    Acceptor acceptor;

    Server(int port) {
        acceptor = new Acceptor(selector, port);
        InputSource source = new InputSource("我加的", System.currentTimeMillis());
        acceptor.addNewConnection(source);
    }

    public void start() {
        //注册事件处理器
        eventLooper.registerEventHandler(EventType.ACCEPT, new AcceptEventHandler(selector));
        new Thread(acceptor, "Acceptor-" + acceptor.getPort()).start();
        eventLooper.handleEvents();
    }
}
